﻿using System;
using System.Windows.Forms;

namespace RegistryGUI
{
    public partial class EditForm : Form
    {
        public string var;
        public string value;
        public string oldVar;
        public string NewVar;
        public EditForm()
        {
            InitializeComponent();
        }
        public void SetText(string name, string value)
        {
            textBox_Var.Text = name;
            textBox_Value.Text = value;
        }
        public void SetSelectTextBox()
        {
            textBox_Value.Focus();
            textBox_Value.SelectAll();
            this.ActiveControl = textBox_Value;//激活当前控件
        }

        public void SetVarReadOnly()
        {
            textBox_Var.ReadOnly = true;
        }
        private void Button_Dir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog选择目录 = new FolderBrowserDialog();
            if (folderBrowserDialog选择目录.ShowDialog() == DialogResult.OK && folderBrowserDialog选择目录.SelectedPath != string.Empty)
            {
                textBox_Value.Text = folderBrowserDialog选择目录.SelectedPath;//得到选中目录
            }
        }

        private void Button_File_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog选择文件 = new OpenFileDialog
            {
                Title = "打开"
            };
            if (openFileDialog选择文件.ShowDialog() == DialogResult.OK && openFileDialog选择文件.FileName != string.Empty)
            {
                textBox_Value.Text = openFileDialog选择文件.FileName;//得到选中文件
            }
        }

        private void Button_OK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            var = textBox_Var.Text;
            value = textBox_Value.Text;
            this.Hide();
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Hide();
        }
    }
}
